<%-- 
    Document   : add_result
    Created on : 2019-6-17, 21:10:45
    Author     : 虎
--%>

<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.jdbc.domains.Usertable1"%>
<%@page import="com.jdbc.dao.impl.Usertable1DaoImpl"%>
<%@page import="com.jdbc.daos.Usertable1Dao"%>
<%@page import="com.jdbc.domains.User"%>
<%@page import="com.jdbc.daos.UserDao"%>
<%@page import="com.jdbc.dao.impl.UserDaoImpl"%>
<%@page language="java" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<%@page import="java.io.*" %>
<%@page import="javax.servlet.*" %>
<%@page errorPage="error.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>注册结果页面！</title>
        <style>
            #yyy{               
                position: absolute;
                top: 120px;
                left: 400px;
                text-align: center;
            }
        </style>
    </head>
    <body style="background:url(myphoto.png);background-size:cover;">
<%
            String name=request.getParameter("name");
            String sex=request.getParameter("sex");
            String ID=request.getParameter("ID");
            String job_number=request.getParameter("job_number");
            String post=request.getParameter("post");
            int post_number=0;
            String birthdays=null;
            Date birthday;
            int age;
            Boolean flag=false;
            String phone=request.getParameter("phone");
            String email=request.getParameter("email");
            String province=request.getParameter("place");
            if(name.equals("")||ID.equals("")||ID.length()!=18||phone.equals("")||email.equals("")||job_number.equals("")){
%>
        <h1 id="yyy">
            注册失败！请检查身份证号是否正确是或有未填项··· 
        </h1>
<%
            }else{
                Usertable1Dao dao = new Usertable1DaoImpl();
                List<Usertable1> allUser= dao.listAll(2);
                for(Usertable1 u1 : allUser){
                    if(post.equals(u1.getPost())){
                        post_number=u1.getPost_number3();flag=true;
                        break;
                    }
                    post_number=u1.getPost_number3();
                }
                if(flag==true){
                    birthdays=ID.substring(6, 14);
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                    birthday=sdf.parse(birthdays);
                    Calendar cal = Calendar.getInstance();
                    int yearNow = cal.get(Calendar.YEAR);
                    int monthNow = cal.get(Calendar.MONTH);
                    int dayNow = cal.get(Calendar.DAY_OF_MONTH);
                    cal.setTime(birthday);
                    int yearBirth = cal.get(Calendar.YEAR);
                    int monthBirth = cal.get(Calendar.MONTH);
                    int dayBirth = cal.get(Calendar.DAY_OF_MONTH);
                    age=yearNow-yearBirth;
                    if(monthNow<=monthBirth){
                        if(monthNow==monthBirth){
                            if(dayNow<dayBirth)age--;
                        }else{
                        age--;
                        }
                    }
                    Usertable1 u = new Usertable1();
                    Usertable1DaoImpl udi=new Usertable1DaoImpl();

                    u.setJob_number1(job_number);
                    u.setPost_number1(post_number);
                    u.setBegin_time(null);
                    u.setEnd_time(null);
                    u.setMonth_salary(0);
                    u.setBonus(0);
                    u.setFine(0);
                    u.setTotal_salary(0);

                    u.setJob_number2(job_number);
                    u.setEmployee_name(name);
                    u.setSex(sex);
                    u.setID(ID);
                    u.setBirthday(new java.sql.Date(birthday.getTime()));
                    u.setAge(age);
                    u.setPhone(phone);
                    u.setProvince(province);
                    u.setEmail(email);

                    u.setPost_number3(post_number);
                    u.setPost(post);
                    udi.save(u);
%>
                    <h1 id="yyy">
                    恭喜新员工<%=name%>添加成功··· <br>
                    </h1>
<%
                }else{
%>
                    <h1 id="yyy">
                    没有该职位,添加失败··· <br>
                    </h1>
<%
                }
            }
%>
    </body>
</html>